#include <stdio.h>

void seed_fill(int array[][40], int x, int y, int m, int n, int tar, int fill, int *cnt)
{
    if (tar == array[x][y] && x >= 0 && x < m && y >= 0 && y < n) {
        (*cnt)++;
        array[x][y] = fill;

        seed_fill(array, x-1, y, m, n, tar, fill, cnt);
        seed_fill(array, x+1, y, m, n, tar, fill, cnt);
        seed_fill(array, x, y-1, m, n, tar, fill, cnt);
        seed_fill(array, x, y+1, m, n, tar, fill, cnt);
    }

    return;
}

int main(int argc, char *argv[])
{
	int m, n, cnt, max, _max, room[40][40];
	int i, j;

	scanf("%d %d", &m, &n);
	for (i=0; i<m; i++) {
		for (j=0; j<n; j++) {
			scanf("%d", &room[i][j]);
		}
	}

    max = 0;
    cnt = 0;
    for (i=0; i<m; i++) {
        for (j=0; j<n; j++) {
            if (room[i][j] == 0) {
                cnt++;
                _max = 0;
                seed_fill(room, i, j, m, n, 0, 1, &_max);
                if (_max > max) max = _max;
            }
        }
    }

    printf("%d %d\n", cnt, max);

	return 0;
}
